package com.wenshi.app.delegate;

import android.content.Context;
import android.view.View;
import android.view.ViewStub;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;

import com.wenshi.app.activity.R;

public class WsDelegateListener implements IDelegateListener {

    public void onShowPageLoading(Context context, ViewStub viewStub, View root) {

        viewStub.setLayoutResource(R.layout.wsview_base_content_loading_defatult);

        viewStub.setVisibility(View.VISIBLE);
        ImageView loading = root.findViewById(R.id.img_loading);

        Animation loadAnimation = AnimationUtils.loadAnimation(context, R.anim.wsview_rotate_animation);

        loading.startAnimation(loadAnimation);
    }

    public void onHidePageLoading(Context context, View root) {


    }

    public void onNoWifi(Context context, ViewStub contentview, View root) {
        contentview.setLayoutResource(R.layout.wsview_base_no_wifi);
        contentview.setVisibility(View.VISIBLE);
        Toast.makeText(context, "抱歉,Wifi没有连接！", Toast.LENGTH_SHORT).show();
    }

    public void onHttpError(Context context, ViewStub viewStub, View root, final WsWiewDelegate.IReLoadContent iReLoadContent) {

        viewStub.setLayoutResource(R.layout.wsview_base_load_error);

        viewStub.setVisibility(View.VISIBLE);

        root.findViewById(R.id.error_btn).setClickable(true);

        root.findViewById(R.id.error_btn).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (iReLoadContent != null)
                    iReLoadContent.onReLoadContent();
            }
        });

    }

    public void onEmpty(Context context, ViewStub contentview, View root) {
        if (contentview != null) {
            contentview.setLayoutResource(R.layout.wsview_base_no_data);
            contentview.setVisibility(View.VISIBLE);
        }
    }
}
